"""
Jiraiya Renamer and Scraper
copyright Artur Figueira 2011 
http://www.arturfigueira.com

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

Jiraiya is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this Jiraiya.  If not, see <http://www.gnu.org/licenses/>.
"""
from utils.Renamer import Renamer
from utils.Scraper import Scraper
from utils.Transfer import Transfer

class Jiraiya(object):
    
    def __init__(self, tvdbCode):
        self.__tvdbCode = tvdbCode
                
    def renameAndScrape(self, sourceDir, destDir=None, extensions=None, deepSearch = True, force = False):
        renamer = self.__internalRename(sourceDir, extensions, deepSearch)
        self.scrape(renamer.renameDir, extensions, force)
        destDir = destDir if destDir is not None else sourceDir
        self.__transfer(renamer.renameDir, destDir)
        renamer.close()
        
    def __internalRename(self, sourceDir, extensions=None, deepSearch = True):
        renamer = Renamer(sourceDir, extensions)
        renamer.deepSearch = deepSearch           
        renamer.rename()
        return renamer
        
    def __transfer(self, sourceDir, destDir):
        transfer = Transfer(sourceDir, destDir)  
        transfer.do_transfer()
    
    def rename(self, sourceDir, destDir=None, extensions=None, deepSearch = True):
        renamer = self.__internalRename(sourceDir, extensions, deepSearch)
        destDir = destDir if destDir is not None else sourceDir
        self.__transfer(renamer.renameDir, destDir)
        renamer.close()
        
    def scrape(self, sourceDir, extensions=None, force = False):
        scraper = Scraper(sourceDir, self.__tvdbCode, extensions)
        scraper.force = force
        scraper.scrap()       